var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var wxcache = require('../../../utils/wxcache.js');



var app = getApp();

Page({
  data: {
    collectList: null,
  },

  onLoad: function (options) {
 
  },
  onReady: function () {

  },
  onShow: function () {
    this.getCollectList();  
    
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  getCollectList() {
    let that = this;
    util.request(api.FavoriteList).then(function (res) {
      console.log(res);
      if (res.code == 200) {
        that.setData({
          collectList: res.responseBody.campaignList
        });
      }
    });
  },
  touchItem: function (e) {
    console.log(e)
    var campaign_id = e.currentTarget.dataset.citem.id;
    wx.navigateTo({
      url: '/pages/goods/goods?id=' + campaign_id,
    })
  },
  deleteItem(e) {

    console.log(e)
    let that = this;

    var citem = e.currentTarget.dataset.citem;
    
    wx.showModal({
      title: '',
      content: '取消收藏？',
      success: function (res) {
        if (res.confirm) {
          var data = {}
          data.flag = 0 // 1 是  0 否
          data.campaignId = citem.id;
          data.userId = wxcache.get("userInfo").id;
          util.request(api.UpdateFavorite, data, 'POST').then(function (res) {
            console.log("收藏返回值")
            console.log(res)
          })
          console.log('用户点击确定')
          that.getCollectList();
        }
      }
    });
  }
})